<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue-light"  :isBack="true" backText="返回" title="系统设置"></cu-custom>
		<view >
		<view v-if="settingList&&settingList.length>0"  class="cu-list menu sm-border" >
			<view class="cu-item arrow" v-for="(item,index) in settingList" :key="index" @tap="menuTap(item)">
				<view class="content">
					<text :class="[item.icon]" :style="[{color:item.color? item.color:''}]" ></text>
					<text >{{item.title}}</text>
				</view>
			</view>
		</view>
		
		</view>
		<view  class="flex flex-direction" style="margin-top: 10rpx;">
			<button class="cu-btn shadow margin-tb-sm lg bg-white"  @tap="logout">退出登入</button>
			<button class="cu-btn shadow margin-tb-sm lg bg-white"   @tap="delShow">注销账号</button>
		</view>
		<view class="flex flex-direction" style="padding-top: 10rpx;">
		</view>
		<u-modal v-model="modelShow"  :content="modelContent" :confirm-color="userType=='20'?'#0081ff':'#f37b1d'"></u-modal>
		<u-modal ref="delModel" :title-style="{color:'#e54d42'}" v-model="delModelShow" title="是否确定注销账号？" confirm-color="#e54d42" content="注销后该账号将被删除" :show-cancel-button="true"  @confirm="delUser"></u-modal>
		
	</view>
</template>

<script>
	import store from "@/store"
	import loginApi from '@/api/system/login.js'
	import api from '@/api/system/setting.js'
	export default {
		data() {
			return {
				userType: store.state.hh_userType,
				settingList:[],
				clientId:store.state.hh_clientId,
				areaCode:store.state.hh_areaCode,
				modelShow:false,
				delModelShow:false,
				modelContent:'功能目前在测试中，尚未开放',
			}
		},
		onReady() {
			this.queryMenu()
			
		},
		methods: {
			queryMenu(){
				const menuDate={}
				if(this.userType=='30'){
					menuDate.menuPro = 'company'
				} else if(this.userType=='20'){
					menuDate.menuPro = 'person'
				} else{
					menuDate.menuPro = 'manager'
				}
				menuDate.areaCode = this.areaCode
				menuDate.clientId=this.clientId
				setTimeout(() => {
					const queryData = Object.assign({},menuDate)
					queryData.menuType = 'setting'
					this.$http.post(api.getMenuList, queryData).then(res => {
						this.settingList=res.result
					}).catch(error => {
						
					})
				}, 50);
			},
			menuTap(item){
				// 点击菜单
				if(item.linkType){
					if(item.linkType=='router'){
						if(item.linkName){
							let flag = false
							for(var num in ROUTES){
								const router = ROUTES[num]
								if(item.linkName == router.name){
									flag = true
									break
								}
							}
							if(flag){
								let params={}
								if(item.param1){//自定义参数1为请求参数，不为空时传入
									try{
										params = JSON.parse(item.param1)
									}catch(e){
										this.modelContent='请求参数（param1）配置必须是json格式'
										this.modelShow = true
										return
									}
								}
								this.$Router.push({ name:item.linkName,params:params})
							}else{
								this.modelContent='功能配置异常，未找到跳转页面'
								this.modelShow = true
							}
						}else{
							this.modelContent='功能目前在测试中，尚未开放'
							this.modelShow = true
						}
					}else if(item.linkType=='h5'){
						if(item.linkUrl){
							this.gotoOhterPage(item.linkUrl)
						}else{
							this.modelContent='功能目前在测试中，尚未开放'
							this.modelShow = true
						}
					}else{
						this.modelContent='功能目前在测试中，尚未开放'
						this.modelShow = true
					}
					
				}else{
					this.modelContent='功能目前在测试中，尚未开放'
					this.modelShow = true
				}
				
			},
			gotoOhterPage(url){
				this.$Router.push({ name:'webView', params: { url:url }})
			},
			logout(){
				const data = {};
				this.$http.post(loginApi.logout, data).then(res => {
					this.$u.vuex('hh_token', '')
					this.$u.vuex('hh_openid', '')
					this.$u.vuex('hh_userType', '')
					this.$u.vuex('hh_user', {})
					uni.removeStorage({key: 'lifeData'});
					this.$Router.replaceAll({ name:'login'})
				}).catch(error => {
					
				})
			},
			delShow(){
				this.delModelShow=true
			},
			delUser(){
				const data = {};
				this.$http.post(api.delUser, data).then(res => {
					this.$u.vuex('hh_token', '')
					this.$u.vuex('hh_openid', '')
					this.$u.vuex('hh_userType', '')
					this.$u.vuex('hh_user', {})
					uni.removeStorage({key: 'lifeData'});
					this.$Router.replaceAll({ name:'login'})
				}).catch(error => {
					
				})
				
			}
		}
	}
</script>

<style lang="scss">

</style>
